Add Encoding.Utf8WithoutBom static extension property#27
Conversation
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/9a5c3164-66fa-4fa3-b551-950f51e9fc94 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/9a5c3164-66fa-4fa3-b551-950f51e9fc94 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/8a41fff1-a0a5-41ff-b43d-8a4cfe44f7d5 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a convenient BOM-less UTF-8 Encoding via a static extension property, plus tests to validate its behavior, to make it easier to create StreamWriter/text output without an emitted BOM.
Changes:
- Introduces
Encoding.Utf8WithoutBombacked by a cachedUTF8Encoding(false)instance. - Adds unit tests asserting UTF-8 identity, empty preamble (no BOM), and non-identity with
Encoding.UTF8.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| PowerKit/Extensions/EncodingExtensions.cs | Adds Encoding.Utf8WithoutBom static extension property backed by a cached encoding instance. |
| PowerKit.Tests/EncodingExtensionsTests.cs | Adds tests covering web name, BOM-less preamble, and distinction from Encoding.UTF8. |
Comments suppressed due to low confidence (1)
PowerKit.Tests/EncodingExtensionsTests.cs:26
- Test method names in this repository consistently use the
..._Testsuffix (and..._Condition_Testfor variants). These new tests omit the suffix, which makes the file inconsistent with the rest of the test suite; please rename the methods to match the existing naming convention.
public void Utf8WithoutBom_Test()
{
// Arrange
var text = "hello, world! 🌍";
// Act
var bytes = Encoding.Utf8WithoutBom.GetBytes(text);
// Assert
Encoding.UTF8.GetString(bytes).Should().Be(text);
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot revert last change, there is no |
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/3e50f80d-751a-4a79-8b1c-d5ee4f17034d Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
|
@copilot merge in latest |
…-utf8withoutbom-extension Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
…tf8WithoutBom Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/4080f2c4-800e-4e10-bfb4-763d281faafc Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Done in 0f4e329. Merged |
|
…ng.UTF8 for BOM handling Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/634e2076-ae0d-4954-8810-0e0ec002275c Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Fixed in 97c15d9.
|
Encoding.UTF8emits a BOM, but there's no convenient analog on theEncodingtype for the BOM-less variant. This adds a static extension propertyUtf8WithoutBombacked bynew UTF8Encoding(false).Changes
PowerKit/Extensions/EncodingExtensions.cs— newextension(Encoding)block exposingUtf8WithoutBomas a static property; instance cached in a private static field on the enclosing classPowerKit.Tests/EncodingExtensionsTests.cs— functional test that encodes text usingUtf8WithoutBomand verifies it is correctly decoded byEncoding.UTF8PowerKit/Extensions/ZipArchiveEntryExtensions.cs— refactored to useEncoding.Utf8WithoutBomfor write methods (no BOM emitted) andEncoding.UTF8for read methods (auto-detects and strips any BOM in the content); entire class wrapped in#if NET40_OR_GREATER || NETSTANDARD || NETsinceZipArchiveEntryis not available in .NET 3.5Usage